
#include <iostream>
#include <string>
#include <functional>
#include "serve.h"
#include "Log.h"
#include "ThreadPool.h"
#include "Intaddr.h"

struct sockaddr_in;

// 调用方式: ./serve port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "使用方式错误,正确调用方式 ./serve port" << std::endl;
        exit(Err_Use);
    }
    zmh::Intaddr serve_addr(AF_INET, std::stoi(argv[1]));

    // 是否传参数取决于是否需要服务类内部进行传参
    auto handler = [](std::string mesage, int fd, const zmh::Intaddr &peer)
    {
        std::string mes = "echo serve#" + mesage;
        ssize_t n = write(fd, mes.c_str(), mes.size());
    };

    zmh::serve ser(serve_addr, handler);
    ser.start();
    return 0;
}
